package com.mz.ozy.mvp.presenter;


import android.app.Activity;
import android.content.Context;
import android.util.Log;

import com.mz.ozy.activity.shop.SortSearchActivity;
import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.GoodsCategoryBean;
import com.mz.ozy.bean.GoodsListBean;
import com.mz.ozy.bean.MeBean;
import com.mz.ozy.bean.ObShopBean;
import com.mz.ozy.bean.TwoTitleBean;
import com.mz.ozy.mvp.model.GoodsListModel;
import com.mz.ozy.mvp.model.MsgModel;
import com.mz.ozy.mvp.view.GoodsListContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class GoodsListPresenter extends BasePresenterImpl<GoodsListContract.View> implements GoodsListContract.Presenter {

    private GoodsListModel mModel;
    //private MsgModel msgModel;

    public GoodsListPresenter() {
        mModel = new GoodsListModel();
        //msgModel = new MsgModel();
    }


    @Override
    public void onSearchGood(Activity activity, String cid, String type, String amtType, String orderBy, String orderType, String pageNo) {
        mModel.onSearchGood(activity, cid, type, amtType, orderBy, orderType, pageNo)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<GoodsListBean>(mView, false) {
                    @Override
                    public void onSuccesss(GoodsListBean bean) {
                        mView.getSearchGoodSuccess(bean);
                    }
                });
    }

    @Override
    public void onSearchGoodByKey(Activity activity, String content, String type, String amtType, String orderBy, String orderType, String pageNo) {
        mModel.onSearchGoodByKey(activity, content, type, amtType, orderBy, orderType, pageNo)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<GoodsListBean>(mView, false) {
                    @Override
                    public void onSuccesss(GoodsListBean bean) {
                        mView.getSearchGoodSuccess(bean);
                    }
                });
    }

    @Override
    public void onSearchGoodByTopic(Activity activity, String cid, String pageNo) {
        mModel.onSearchGoodByTopic(activity, cid, pageNo)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<GoodsListBean>(mView, false) {
                    @Override
                    public void onSuccesss(GoodsListBean bean) {
                        mView.getSearchGoodSuccess(bean);
                    }
                });
    }

    @Override
    public void getGoodsCategory(Context context) {
        mModel.getGoodsCategory(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<GoodsCategoryBean>(mView, false) {
                    @Override
                    public void onSuccesss(GoodsCategoryBean bean) {
                        mView.getGoodsCategoryData(bean);
                    }
                });
    }

    @Override
    public void getGoodsTopic(Context context) {
        mModel.getGoodsTopic(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<GoodsCategoryBean>(mView, false) {
                    @Override
                    public void onSuccesss(GoodsCategoryBean bean) {
                        mView.getGoodsTopicData(bean);
                    }
                });
    }

    @Override
    public void getTwoTitle(Context context, String id) {
        Log.e("TAG", "id=" + id);
        mModel.getTwoTitle(context, id)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<TwoTitleBean>(mView, false) {
                    @Override
                    public void onSuccesss(TwoTitleBean bean) {
                        mView.getTwoTitleSuccess(bean);
                    }
                });
    }
    @Override
    public void getListData(Context context, String page, String orderBy, String type, String content, String orderType) {
        mModel.getDataList(context,page,orderBy,type,content,orderType)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<GoodsListBean>(mView) {

                    @Override
                    public void onSuccesss(GoodsListBean bean) {
                        mView.showListData(bean);
                    }
                });
    }
}
